<?php
#this is the dictionnary
$titre_page="Dictionnaire russe-français";
include("header.inc.php");
include("clavier.inc.php"); //insertion du clavier russe

?>

<script type="text/javascript">
function confirmer(id) {
  var r=confirm("Effacer l'enregistrement?");
  if (r==true)  {
  document.location.href="deleteDictionnary.php?id="+id;
  return true;
 }
  else {
  return false;
  }
  }
</script>
  

<h1><? echo $titre_page; ?></h1>
<div class="level1">

<p>

</p>
<form method="GET">
<? 
#on inclut la liste alphabétique de la langue à apprendre
include("alphabet.inc.php"); 
?>
<br><input name="cherche" type="text" id="traduction">
<select name="sens">
<option value="frru">&nbsp;français->russe&nbsp;</option>
<option value="rufr">&nbsp;russe->français&nbsp;</option>
</select>
<input value="Annuler" type="reset">

<input value="Traduire / chercher" type="submit">
 | <a href="newDictionnary.php">Nouveau mot</a><br>

</form>

</div>

<?
############ debut calculs ############


$alpha=$_GET['alpha'];
$cherche=$_GET['cherche'];
$sens=$_GET['sens'];
if(!$sens){
$sens="rufr";
}


#if(isset($alpha)&&!isset($cherche)) {
if($sens=="rufr") {
if (isset($cherche)&&strlen($cherche)>0) {
#$sql= "SELECT * FROM `" .$latable ."` WHERE foreign LIKE '$cherche%' OR local LIKE '$cherche%'  ORDER BY foreign";
#new: search local only as it is a translator
 $sql = "SELECT * FROM `" .$latable ."` WHERE `foreign` LIKE '" .$cherche ."%' ORDER BY `local`"; 
#echo "<br>cherche: " .$cherche;
}elseif(isset($alpha)&&strlen($cherche)<1) {
	$sql = "SELECT * FROM `" .$latable ."` WHERE `foreign` LIKE '$alpha%' ORDER BY `foreign`";
#echo "alpha: " .$alpha;
}
} else {
if (isset($cherche)&&strlen($cherche)>0) {
#$sql= "SELECT * FROM `" .$latable ."` WHERE foreign LIKE '$cherche%' OR local LIKE '$cherche%'  ORDER BY foreign";
#new: search local only as it is a translator
 $sql = "SELECT * FROM `" .$latable ."` WHERE `local` LIKE '" .$cherche ."%' ORDER BY `local`"; 
#echo "<br>cherche: " .$cherche;
}elseif(isset($alpha)&&strlen($cherche)<1) {
	$sql = "SELECT * FROM `" .$latable ."` WHERE `foreign` LIKE '$alpha%' ORDER BY `foreign`";
#echo "alpha: " .$alpha;
}
}
#echo $sql; //tests
$sqlR=mysql_query($sql);
$sqlN=mysql_num_rows($sqlR);
$i=0;


if($sqlN>0){ //il y a eu une recherche
echo "<h2>Total mots trouvés: " .$sqlN ."</h2>";

############ debut resultats ############

echo "<table><tr><th>" .$langue ."</th><th>français</th><th>genre</th><th>modifier</th><th>effacer</th></tr>";
while($i<$sqlN) {
	$test=($i/2)-intval($i/2);
if($test=="0") {
	$styleLigne="pair";
} else {
	$styleLigne="impair";
	}
	
	
	
	echo "<tr class=\"" .$styleLigne ."\">";
	$id=mysql_result($sqlR,$i,'id');
	
$foreign=mysql_result($sqlR,$i,'foreign');
$local=mysql_result($sqlR,$i,'local');
$type=mysql_result($sqlR,$i,'type');
echo "<td>" .$foreign ."</td>";
echo "<td>" .$local ."</td>";
echo "<td>" .$type ."</td>";

echo "<td class=\"cellule_action\"><a href=\"editDictionnary.php?id=" . $id ."\"><img src=\"common/b_edit.png\" alt=\"modifier\" title=\"modifier\"></a></td>"; 
echo "<td class=\"cellule_action\"><img src=\"common/b_empty.png\" onclick='confirmer(" .$id.")' alt=\"effacer\" title=\"effacer\"></td>"; 
$i++;
echo "</tr>\n";
}
echo "</table>";
}
include("footer.inc.php");
?>


